<#include "../common/_contentHeader.html"/>
<@layout location="新增班次" subLocation="<a href='#' onclick=\"loadUIAndRender( 'plan', 'WEB-INF/views/planset/plan.html')\">班次设置</a> / 新增班次" />
<div class="main-content">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#home" data-toggle="tab">新增</a></li>
    </ul>
    <div class="row">
        <div class="col-sm-8">
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane active" id="home">
                    <#include "_form.html"/>
                     <div class="btn-toolbar list-toolbar">
                            <button class="btn btn-primary" id="addPlanBtn"><i class="fa fa-save"></i> 保存</button>
                        </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
$(document).ready(function($) {
    $("#inputDefineType").val(2);
    $("#inputPlanType").val(1);
    //保存
    seajs.use('app/planset/index',function(index){
        $("#addPlanBtn").click(function(){
            index.addPlan();
        });
    });
     //配色
    $("#bcgl_color_img").bigColorpicker(function(el,color){
        $(el).css("background-color",color);
        $("#inputColor").val(color);
    });
    //datetimepicker日期选择控件
    $('#planStartTime').datetimepicker({
        language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 1,
        minView: 0,
        maxView: 1,
        forceParse: 0
    }).on('changeDate', function(ev){
        planTimeChange(ev);
    });
     $('#planEndTime').datetimepicker({
        language:  'fr',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 1,
        minView: 0,
        maxView: 1,
        forceParse: 0
    }).on('changeDate', function(ev){
        planTimeChange(ev);
    });
});
//计算总时间
function planTimeChange(e) {
    $("#updatePlanForm").data('bootstrapValidator').resetForm();
    $("#updatePlanForm").data('bootstrapValidator').validate();
    var sTime =  $('#inputStartTime').val();
    var eTime = $('#inputEndTime').val();
    $('#inputPeriodTime').val(sTime + "-" + eTime);

    if (sTime) {
        var sTime0 = sTime.split(":")[0];
        var sTime1 = (sTime.split(":")[1] / 60).toFixed(1);
        sTime = Number(sTime0) + Number(sTime1);
    }
    if (eTime) {
        var eTime0 = eTime.split(":")[0];
        var eTime1 = (eTime.split(":")[1] / 60).toFixed(1);
        eTime = Number(eTime0) + Number(eTime1);
    }
    var totalTime = Number((eTime - sTime).toFixed(1));
    if (totalTime < 0) {
        $('#inputTotalTime').val(Number(totalTime)+24);
    }else{
        $('#inputTotalTime').val(totalTime);
    }
}
</script>
